/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CapadeDatos;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import modelo.beansemestre;

/**
 *
 * @author jxtx
 */
public class daosemestre2 {
    public void insertarsem(int cod_turno,String cod_per,String cod_carrera, String descripcion, String inicio,String fin){
        Boolean verdad = false;
        ArrayList lista = new ArrayList();
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="CALL `ingresar_sem`('"+ cod_carrera + "',"
                      + " '"+ cod_turno + "',"
                       + " '"+ cod_per + "',"
                       + " '"+ descripcion + "','"+ inicio + "','"
                       + fin + "');";
//CALL `ingresar_sem`('carCONTA', '10', '2011-I', 'II', '2010-12-12', '2011-01-01')
            if(stm.executeQuery(sql).wasNull()){
               verdad = false;
               JOptionPane.showMessageDialog(null,"NO INGRESADO");
            }
            else {
                verdad = true;
                JOptionPane.showMessageDialog(null,"INGRESADO");
            }
    }catch(Exception e){System.out.print(e);

}
}
    public static beansemestre semestre(String COD_SEM){

    beansemestre p  = new  beansemestre();

     try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql =" select s.cod_sem,c.nombre_carrera,s.descripcion,"
 +" s.cod_periodo,t.descripcion,s.inicio,s.fin,s.Estado from semestre as s "
 +" inner join carrera as c on c.cod_carrera=s.cod_carrera"
 +" inner join turno as t on t.cod_turno=s.cod_turno "
 +" where s.cod_sem='"+COD_SEM+"';"; // PROCEDIMIENTO ALMACENADO

            ResultSet rs =stm.executeQuery(sql);

            while (rs.next()){
                   p.setCod_sem(rs.getString(1));
                   p.setCod_carrera(rs.getString(2));
                   p.setDescipcion(rs.getString(3));
                   p.setCod_per(rs.getString(4));
                   p.setTurno(rs.getString(5));
                   p.setFechaini(rs.getString(6));
                   p.setFechafin(rs.getString(7));
                   p.setEstado(rs.getString(8));
  }


            if(rs.wasNull()){
                JOptionPane.showMessageDialog(null,"NO INGRESADO");

            }
            else {

             JOptionPane.showMessageDialog(null,"encontrado "+ COD_SEM);

        }

    }catch(Exception e){System.out.print(e);
   }
        return p;
   }

    public void modsem(String cod_sem,int cod_turno,String cod_per,String cod_carrera, String descripcion, String inicio,String fin){
        Boolean verdad = false;
        ArrayList lista = new ArrayList();
        int k;
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="update semestre set "
                    + "semestre.cod_turno='"+cod_turno+"'"
                    + ",semestre.cod_periodo='"+cod_per+"',"
                    +" semestre.cod_carrera='"+cod_carrera+"',"
                    + "semestre.descripcion='"+descripcion+"',"
                    + " semestre.inicio='"+inicio+"',"
                    + "semestre.fin='"+fin+"' "
                    + "where semestre.cod_sem='"+cod_sem+"';";
//CALL `ingresar_sem`('carCONTA', '10', '2011-I', 'II', '2010-12-12', '2011-01-01')
            k=stm.executeUpdate(sql);
            if(k!=1)
            {
               verdad = false;
               JOptionPane.showMessageDialog(null,"NO INGRESADO");
            }
            else {
                verdad = true;
                JOptionPane.showMessageDialog(null,"INGRESADO");
            }
    }catch(Exception e){System.out.print(e);

}
}
}
